package com.example.primarycalculator2;

import androidx.annotation.Nullable;
import androidx.appcompat.app.AppCompatActivity;

import android.annotation.SuppressLint;
import android.content.Intent;
import android.os.Bundle;
import android.util.Log;
import android.view.Gravity;
import android.widget.ArrayAdapter;
import android.widget.CheckBox;
import android.widget.Spinner;

import com.ashokvarma.bottomnavigation.BottomNavigationBar;
import com.ashokvarma.bottomnavigation.BottomNavigationItem;
import com.ashokvarma.bottomnavigation.ShapeBadgeItem;
import com.ashokvarma.bottomnavigation.TextBadgeItem;

public class NavigatorTestActivity2 extends AppCompatActivity implements  BottomNavigationBar.OnTabSelectedListener{
    BottomNavigationBar bottomNavigationBar;



    int lastSelectedPosition = 0;
    public static final String  TAG="Navi";

    @Nullable
    TextBadgeItem numberBadgeItem;

    @Nullable
    ShapeBadgeItem shapeBadgeItem;


    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_navigator_test2);

        bottomNavigationBar = findViewById(R.id.bottom_navigation_bar);



        bottomNavigationBar.setTabSelectedListener(this);


        refresh();
    }


    @SuppressLint("WrongConstant")
    private void refresh() {

        bottomNavigationBar.clearAll();
//        bottomNavigationBar.setFab(fabHome, BottomNavigationBar.FAB_BEHAVIOUR_TRANSLATE_AND_STICK);
//        bottomNavigationBar.setFab(fabHome);


        numberBadgeItem = new TextBadgeItem()
                .setBorderWidth(4)
                .setBackgroundColorResource(R.color.blue)
                .setText("" + lastSelectedPosition)
                .setHideOnSelect(false);

        shapeBadgeItem = new ShapeBadgeItem()
                .setShape(5)
                .setShapeColorResource(R.color.teal)
                .setGravity(Gravity.TOP | Gravity.END)
                .setHideOnSelect(false);

        numberBadgeItem.toggle();
        shapeBadgeItem.toggle();


        bottomNavigationBar.setMode(2);
//        bottomNavigationBar.setBackgroundStyle(bgSpinner.getSelectedItemPosition());
//        Log.d(TAG, "refresh: "+modeSpinner.getSelectedItemPosition());

        bottomNavigationBar
                .addItem(new BottomNavigationItem(R.drawable.ic_location_on_white_24dp, "Nearby").setActiveColorResource(R.color.orange).setBadgeItem(numberBadgeItem))
                .addItem(new BottomNavigationItem(R.drawable.ic_find_replace_white_24dp, "Find").setActiveColorResource(R.color.teal))
                .addItem(new BottomNavigationItem(R.drawable.ic_favorite_white_24dp, "Categories").setActiveColorResource(R.color.blue).setBadgeItem(shapeBadgeItem))
                .setFirstSelectedPosition(lastSelectedPosition > 2 ? 2 : lastSelectedPosition)
                .initialise();

    }



    @Override
    public void onTabSelected(int position) {
        lastSelectedPosition = position;
        Log.d(TAG, "onTabSelected: "+lastSelectedPosition);
        switch (lastSelectedPosition){
            case 2:
                Intent intent=new Intent(NavigatorTestActivity2.this,MainActivity.class);
                startActivity(intent);
                break;
            default:
                break;
        }
//       跳转Activity
    }

    @Override
    public void onTabUnselected(int position) {
        Log.d(TAG, "onTabUnselected: ou");
    }

    @Override
    public void onTabReselected(int position) {
        Log.d(TAG, "onTabReselected: 则了");
    }
}